'''
参考第9节的综合案例中的学生信息管理，来实现一个自动取款机的存取款模拟效果。
要求有登陆和退出、查询余额、取钱，存钱等操作
'''
#银行账户信息
num=0
bankCount=[
    {'Username':'Tony','Password':700966,'Balance':30000},
    {'Username':'Will','Password':710420,'Balance':70897},
    {'Username':'Jack','Password':951109,'Balance':23200},
]
#显示用户界面
def showOS():
    print("=" * 12, "银行管理系统", "=" * 12)
    print("{0:10} {1:10}".format("      1.查询余额", "     2.实时取款"))
    print("{0:10} {1:10}".format("      3.实时存款", "     4.退出系统"))
    print("=" * 38)
#查询账户余额
def showBalance():
    print("=" * 12, "您的账户余额", "=" * 12)
    print(bankCount[i]['Balance'],"元")
    print("=" * 38)
#取款
def withdrawal(num):
    while True:
        num = int(input('请输入取款金额:'))
        if num>bankCount[i]['Balance']:
            print('您的账户余额不足,请重新输入.')
            print("=" * 38)
        else:
            bankCount[i]['Balance']-=num
            print('取款成功.您的账户余额为:',bankCount[i]['Balance'])
            print("=" * 38)
            break
#登陆
un=input('请输入用户名:')
for i in range(len(bankCount)):
    if un==bankCount[i]['Username']:
        pw=input('请输入密码:')
        if int(pw)==bankCount[i]['Password']:
            showOS()
            while True:
                key = input("请输入对应的序号进行操作：")
                if key == '1':
                    showBalance()
                elif key == '2':
                    print("=" * 14, "实时取款", "=" * 14)
                    withdrawal(num)
                elif key == '3':
                    num = int(input('请输入存款金额:'))
                    bankCount[i]['Balance']+=num
                    print('存款成功.您的账户余额为:', bankCount[i]['Balance'])
                    print("=" * 38)
                elif key == '4':
                    print('欢迎下次使用,再见!')
                    break
                else:
                    print('输入有误,请重新输入.')
        else:
            print('密码错误.')
    else:
        i+=1